import { axios } from "@/services/axios";

// function  getDetails(id)
// {
//   OrgStruct.get(id).then(data => {
//     return data.details || [];
//   })
// }

function itemsHasChildren(items)
{
  var is_tree = false;
  for (var item in items) {
    if (item.hasOwnProperty("children")) {
      is_tree = true;
      break;
  }}
  return is_tree;
}

const OrgStruct = {
  query: orgstruct_enum => axios.get(`api/orgstructs/${orgstruct_enum}`),
  create: (orgstruct_enum, data) => axios.post(`api/orgstructs/${orgstruct_enum}`, data),
  get: id => axios.get(`api/orgstruct/${id}`),
  save: (id,data) => axios.post(`api/orgstruct/${id}`, data),
  delete: id => axios.post(`api/orgstruct/delete/${id}`),
  match: (orgstruct_enum, effect_date) => axios.get(`api/orgstruct/match/${orgstruct_enum}`, {effect_date: effect_date}),
  //getDetails,
  itemsHasChildren,
};

export default OrgStruct;
